package com.ruoyi.tgis.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.tgis.mapper.CatalogInfoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.tgis.mapper.AllServerMapper;
import com.ruoyi.tgis.domain.AllServer;
import com.ruoyi.tgis.service.AllServerService;

/**
 * 服务基础信息Service业务层处理
 * 
 * @author ljj
 * @date 2024-06-24
 */
@Service
public class AllServerServiceImpl implements AllServerService {

    private static Logger logger = LoggerFactory.getLogger(AllServerServiceImpl.class);

    @Autowired
    private AllServerMapper allServerMapper;

    @Autowired
    private CatalogInfoMapper catalogInfoMapper;

    /**
     * 查询服务基础信息
     * 
     * @param id 服务基础信息主键
     * @return 服务基础信息
     */
    @Override
    public AllServer selectAllServerById(Long id){
        return allServerMapper.selectAllServerById(id);
    }

    /**
     * 查询服务基础信息列表
     * 
     * @param allServer 服务基础信息
     * @return 服务基础信息
     */
    @Override
    public List<AllServer> selectAllServerList(AllServer allServer){
        List<AllServer> allServers = allServerMapper.selectAllServerList(allServer);
        Map<String,Object> serverCatalogMap = new HashMap<>();
        List<Map<String, String>> serverIdAndCatalogNameList = catalogInfoMapper.getServerIdAndCatalogName();
        if(serverIdAndCatalogNameList != null && serverIdAndCatalogNameList.size()>0){
            for (Map item : serverIdAndCatalogNameList) {
                serverCatalogMap.put(String.valueOf(item.get("serverId")),item.get("catalogName"));
            }
        }
        for (AllServer item :allServers) {
            item.setCatalogName((String)serverCatalogMap.get(String.valueOf(item.getId())));
        }
        return allServers;
    }

    /**
     * 新增服务基础信息
     * 
     * @param allServer 服务基础信息
     * @return 结果
     */
    @Override
    public int insertAllServer(AllServer allServer){
        allServer.setCreateTime(DateUtils.getNowDate());
        return allServerMapper.insertAllServer(allServer);
    }

    /**
     * 修改服务基础信息
     * 
     * @param allServer 服务基础信息
     * @return 结果
     */
    @Override
    public int updateAllServer(AllServer allServer){
        allServer.setUpdateTime(DateUtils.getNowDate());
        return allServerMapper.updateAllServer(allServer);
    }

    /**
     * 批量删除服务基础信息
     * 
     * @param ids 需要删除的服务基础信息主键
     * @return 结果
     */
    @Override
    public int deleteAllServerByIds(Long[] ids){
        return allServerMapper.deleteAllServerByIds(ids);
    }

    /**
     * 删除服务基础信息信息
     * 
     * @param id 服务基础信息主键
     * @return 结果
     */
    @Override
    public int deleteAllServerById(Long id){
        return allServerMapper.deleteAllServerById(id);
    }

    @Override
    public void serverTaskDemo(Integer i) {
        if(i==null){
            logger.info("测试无参执行");
        }else{
            for (int j = 0; j < i; j++) {
                logger.info("测试有参执行：" + j);
            }
        }
    }
}
